import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;

public class PDECODE {
    private StringTokenizer st;
    private void run() throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        while(true){

           st = new StringTokenizer(bf.readLine());

           int n = Integer.parseInt(st.nextToken());
           long m = Long.parseLong(st.nextToken());
           int arr [] = new int[n+1];
           boolean dis [] = new boolean[n+1];

           if(n==0 && m==0) break;

           st = new StringTokenizer(bf.readLine());
           for(int i=1;i<=n;++i) arr[i] = Integer.parseInt(st.nextToken());
           for(int i=1;i<=n;++i) dis[i] = false;
           String input = bf.readLine();

           char res [] = new char [n+1];

           for(int i=1;i<=n;++i) if(dis[i]==false) {
               int x = i; int ct = 0;
               while(dis[x]==false){
                   dis[x] = true; x = arr[x]; ct++;
               }
               int shift = (int)(m%ct);
               int a = i; int b = i;
               for(int j=0;j<shift;++j) b = arr[b];
               for(int j=1;j<=ct;++j){
                   res[b] = input.charAt(a-1); a = arr[a]; b = arr[b];
               }
           }

           for(int i=1;i<=n;++i) System.out.print(res[i]);
           System.out.println("");

        }
    }
    public static void main ( String [] Args ) throws Exception {
        new PDECODE().run();
    }
}